# -*- coding: utf-8 -*-
import re

import scrapy


class ZiruSpider(scrapy.Spider):
    name = 'ziru'
    allowed_domains = ['ziroom.com']
    start_urls = ['http://cd.ziroom.com/z/p1/']
    page = 1
    def parse(self, response):
        a_list = response.xpath("//div//div[@class='info-box']")
        for a_temp in a_list:
            title01 = a_temp.xpath("./h5/a/text()").extract_first()
            floor01 = a_temp.xpath("./div[@class='desc']/div[1]/text() ").extract_first()
            adr = a_temp.xpath("./div[@class='desc']/div[2]/text()").extract_first()
            price01 = a_temp.xpath("./div[@class='price ']/span/@style").extract_first()

            # title = re.findall(r"·(.+?)-", title01)
            # direction = re.findall(r"-(.+?)", title01)

            yield {
                '标题': title01,
                '层数': floor01,
                '地点': adr,
                '价格': price01
            }

            self.page += 1
            if self.page <= 5:
                news_url = 'http://cd.ziroom.com/z/p%d/' % self.page
                yield scrapy.Request(url=news_url, callback=self.parse)
